
{% if entity.id is  null %}
<form  id="form"  class="form-horizontal" action="{{ path('resolucion_create') }}" method="post" {{ form_enctype(form) }}>

{% elseif entity.id is not null %}
    <form  id="form"  class="form-horizontal" action="{{ path('resolucion_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(form) }}>

{% else %}
{% endif %}

{{ form_errors(form) }}


{{ form_widget(form._token) }}  

        <fieldset>
            <legend>Editar Resolución</legend>
            <div class="span7">

                <div class="control-group">
                    <label class="control-label required">N&uacute;mero</label>
                    <div class="controls">
                {{ form_errors(form.numero) }}
                   {{ form_widget(form.numero) }}
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label required" >Fecha</label>
                {{ form_errors(form.fecha) }}
                        <div class="controls">
                   {{ form_widget(form.fecha) }}
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label required">Observaci&oacute;n</label>
                {{ form_errors(form.observacion) }}
                            <div class="controls">
                   {{ form_widget(form.observacion) }}
                                </div>
                            </div>
                            <div class="control-group">
                                <div class="controls">
                                    <a href="{{ path('resolucion_update', { 'id': entity.id }) }}" data-row="resolucion-{{entity.id}}"  type="submit" class="btn btn-warning save"><i class="icon-edit"></i> Guardar</button>
                                        <a class="btn btn-cancel" href="{{ path('concurso') }}">Cancelar</a>
                                </div>
                            </div>
                        </div>
                        <fieldset>
                            </form>



                            <script type="text/javascript">
    $(function(){
            $(".btn-cancel").on('click', function(e){
                e.preventDefault();
                closeDialog();
        });
      $('.date').datepicker({ dateFormat: 'dd/mm/yy' });
      
  
      $(".save").on('click',function(e){
          e.preventDefault();
           var $this =  $(this);
                    var to_go = $this.attr('href');
                    var $row = $("#"+$this.attr('data-row'));
                     var to_send = $("#form").formParams();  
                  if(validateAjaxInputs()){
                  $.ajax({
                    url:to_go,
                    type:'POST',
                     data:to_send,
                    beforeSend:function(){
                        $('#form').spin();
                },
                    complete:function(data){
                         $('#form').spin(false);
                       var result =$.evalJSON(data.responseText);
                       if(result.status){
                          updateRow($row.children(),result.entity);
                          showMsj(result);
                          $("#target-dialog").dialog('close');
                       }else{
                              $.each(result.errors, function(i,e){
                                               console.log("e",e);
                                               $(e.key).parent().append('<span class="help-block">'+e.msj+'</span>').parent().addClass("error");
                                           });
                       }
                       
                       
                }
                
                
            })//fin ajax
                }   
                
            });//fin click
            
            
                function validateAjaxInputs() {
                          $.validity.setup({outputMode:"bootstrap"});
  

    $.validity.start();
    
    $("#ResolucionType_numero")                        
        .require("Es obligatorio")       
        .match("integer","Debe ser un nro.")
        .greaterThan(0,"Debe ser mayor a 0");
        
    $("#ResolucionType_fecha")                        
         .require("Es obligatorio") 
        .match("date","Debe ser una fecha con formato dd/mm/aaaa valido.");
  
              
    var result = $.validity.end();
    
    // Return whether it's okay to proceed with the Ajax:
    return result.valid;
                       }
            
            
                function getInputPosition(){
          return ['numero','fecha','observacion','oficina'];
  }
            
            function updateRow($childrens,array_values){
            var inputs = getInputPosition();
            console.log("hijos",$childrens);
            $.each($childrens, function(i,el){
                if( $(el).find('a').length ==0 ){
                $(el).text(array_values[inputs[i]])
                }
            });}

            
           function closeDialog(){$("#target-dialog").dialog('close');}
           function showMsj(response){
              if(response.status){                                
              $("#freeow").freeow("",response.mensaje, {
                                classes: ["gray"],
                                autoHide: true
                    });
              }else{
                  
                  $each(response.mensaje,function(i,ele){
                      output += '<div class="alert">'  + ele +'</div>'
              });
              }
              var time = response.mensaje.length * 400;
              setTimeout(function(){
                  $("#errors").find('div.alert').hide('fade',{},350)
              
          },time);

      }
          
 
});
    
                                </script>

